package com.hlcl.huaji.ctrl;

import android.app.Dialog;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.ListView;
import android.widget.TextView;

import com.elcl.adapter.AbViewHolder;
import com.elcl.adapter.BaseLVAdapter;
import com.elcl.storage.ApplicationCache;
import com.hlcl.huaji.R;
import com.tbc.android.mdl.util.StringUtils;

import java.util.ArrayList;
import java.util.List;


/**
 * Created by lichunlin on 16/4/14.
 */
public class DialogUtils {

    /**
     * 点击确定的对话框
     */
    public static void showChooseDialog(final Context mContext, String[] content, final ClickRight clickRight) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.dialog_choose,
                null);
        final Dialog dialog = new Dialog(mContext, R.style.MyDialog);
        dialog.setContentView(view);
        dialog.setCancelable(true);
        dialog.show();

        TextView txt_title = (TextView) view.findViewById(R.id.txt_title);
        TextView txt_content = (TextView) view.findViewById(R.id.tv_content);
        Button btn_cancel = (Button) view.findViewById(R.id.btn_cancel);
        Button btn_sure = (Button) view.findViewById(R.id.btn_sure);

        if (StringUtils.isNotEmpty(content[1])) {
            txt_content.setVisibility(View.VISIBLE);
            txt_content.setText(content[1]);
        } else {
            txt_content.setVisibility(View.GONE);
        }

        if (StringUtils.isNotEmpty(content[0]))
            txt_title.setText(content[0]);
        else
            txt_title.setVisibility(View.INVISIBLE);

        btn_cancel.setText(content[2]);
        btn_sure.setText(content[3]);

        btn_cancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dialog.dismiss();
                clickRight.clickCancle();
            }
        });
        btn_sure.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                clickRight.clickSure();
                dialog.dismiss();
            }
        });
    }

    public interface ClickInputResult {
        void clickSure(String content);
    }

    public interface ClickRight {
        void clickSure();

        void clickCancle();
    }


    /**
     * 点击确定的对话框
     */
//    public static void showOrderChooseOrderTypeDialog(final Context mContext, String typeChoose, final ClickInputResult clickInputResult) {
//        View view = LayoutInflater.from(mContext).inflate(R.layout.dialog_choose_order_type,
//                null);
//        final Dialog dialog = new Dialog(mContext, R.style.MyDialog);
//        dialog.setContentView(view);
//        dialog.setCancelable(true);
//        dialog.show();
//
//        String[] content = new String[]{"绿色管", "安心管", "橙色管", "抗菌管"};
//        final List<String> orderTypeList = new ArrayList<>();
//        for (int i = 0; i < content.length; i++) {
//            orderTypeList.add(content[i]);
//        }
//
//        ListView lv_content = (ListView) view.findViewById(R.id.lv_content);
//        OrderTypeAdapter orderTypeAdapter = new OrderTypeAdapter(orderTypeList,R.layout.adapter_simple_base);
//        orderTypeAdapter.setTypeChoose(typeChoose);
//        lv_content.setAdapter(orderTypeAdapter);
//        lv_content.setOnItemClickListener(new AdapterView.OnItemClickListener() {
//            @Override
//            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
//                clickInputResult.clickSure(orderTypeList.get(position));
//                dialog.dismiss();
//            }
//        });
//    }
//
//    private static class OrderTypeAdapter extends BaseLVAdapter<String> {
//
//        private String typeChoose;
//        //设置类型
//        public void setTypeChoose(String typeChoose){
//            this.typeChoose = typeChoose;
//        }
//
//        public OrderTypeAdapter(List<String> list, int idLayout) {
//            super(list, idLayout);
//        }
//
//        @Override
//        public View getItemView(int position, View convertView, ViewGroup parent) {
//            TextView txt_title = (TextView) AbViewHolder.getView(convertView,R.id.txt_title);
//
//            String title = list.get(position);
//            if (title.equals(typeChoose)){
//                txt_title.setTextColor(ApplicationCache.context.getResources().getColor(R.color.app_theme));
//            }else{
//                txt_title.setTextColor(ApplicationCache.context.getResources().getColor(R.color.text_black));
//            }
//            txt_title.setText(title);
//
//            return convertView;
//        }
//    }


}

